package com.example.springbootsfzy.controller.gengyifei;

import com.example.springbootsfzy.domain.ChargeStandardAssociations;
import com.example.springbootsfzy.service.gengyifei.charge_standard_associations_service;
import com.example.springbootsfzy.util.R;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
收费标准关联表  接口
 */
@RestController
@RequestMapping("/charge_standard_associations")
public class charge_standard_associations_controller {
    @Autowired
    private charge_standard_associations_service service;
    //通过  关联id  删除关联信息
    @DeleteMapping("/delete")
    public R deleteByPrimaryKey(int association_id){
        int i = service.deleteByPrimaryKey(association_id);
        if(i>0){
            return R.ok(null);
        } else if(i==0) {
            return R.fail("找不到要删除的对象");
        }
        return R.error("删除失败");
    }

    //通过参数信息  增加收费关联信息
    @PostMapping("/add")
    public R insert(ChargeStandardAssociations record){
        int i = service.insert(record);
        if(i>0){
            return R.ok(null);
        }
        return R.fail("添加失败");
    }

    //通过参数信息  修改关联信息
    @PutMapping("/update")
    public R update(ChargeStandardAssociations record){
        int i = service.updateByPrimaryKey(record);
        if(i>0){
            return R.ok(null);
        }
        return R.fail("修改失败");
    }

    //通过关联id  查询关联信息
    @GetMapping("/selectbyid")
    public R selectByPrimaryKey(int association_id){
        ChargeStandardAssociations chargeStandardAssociations = service.selectByPrimaryKey(association_id);
        if(chargeStandardAssociations!=null){
            return R.ok(chargeStandardAssociations);
        }
        return R.fail("查不到关联信息");
    }

    //查询所有关联信息
    @GetMapping("/selectAll")
    public R selectAll(){
        List<ChargeStandardAssociations> chargeStandardAssociations = service.selectAll();
        if(chargeStandardAssociations!=null){
            return R.ok(chargeStandardAssociations);
        }
        return R.fail("查不到关联信息");
    }
}
